package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /*添加用户*/
    @ApiOperation("添加用户信息")
    @PostMapping("/addUser")
    public int AddUser(User user) {
        return userService.insertUser(user);
    }

    /*删除用户*/
    @ApiOperation("按照Id删除用户信息")
    @GetMapping("/deleteUserById")
    public int DeleteUserById(int id) {
        return userService.deleteUserById(id);
    }

    /*更新用户*/
    @ApiOperation("修改用户信息")
    @GetMapping("/updateUser")
    public int updateUser(User user) {
        return userService.updateUser(user);
    }

    /*查询所有用户信息*/
    @ApiOperation("查找用户信息")
    @GetMapping("/selectAllUser")
    public List<User> selectAllUser() {
        return userService.selectAllUser();
    }

    /*根据Id查询用户信息*/
    @ApiOperation("根据Id查找用户信息")
    @GetMapping("/selectUserById")
    public User selectUserById(int id) {
        return userService.selectUserById(id);
    }
}
